package com.zsgeek.wisdchain.qutu.tools;

import android.support.annotation.StringRes;
import android.view.Gravity;
import android.widget.Toast;

import com.zsgeek.wisdchain.qutu.QuTuApplication;


public class ToastHelper {

    private static Toast mToast;

    /**
     * 描述：Toast提示文本.
     *
     * @param resId 文本的资源ID
     */
    public static void showToast(@StringRes int resId) {
        show(QuTuApplication.getInstance().getResources().getString(resId), Toast.LENGTH_SHORT);
    }

    /**
     * 描述：Toast提示文本.
     * <p/>
     * 默认提示Toast
     */
    public static void showToast(String resStr) {
        show(resStr, Toast.LENGTH_SHORT);
    }

    /**
     * 长提示
     * 描述：Toast提示文本.
     *
     * @param resId 文本的资源ID
     */
    public static void showLongToast(@StringRes int resId) {
        show(QuTuApplication.getInstance().getResources().getString(resId), Toast.LENGTH_LONG);
    }

    /**
     * 长提示
     * 描述：Toast提示文本.
     * <p/>
     * 默认提示Toast
     */
    public static void showLongToast(String resStr) {
        show(resStr, Toast.LENGTH_LONG);
    }

    /**
     * @param duration
     **/
    public static void show(String text, int duration) {
        if (text == null || text.length() == 0)
            return;
        if (mToast == null) {
            mToast = Toast.makeText(QuTuApplication.getInstance(), text, duration);
        }
        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.setText(text);
        mToast.show();
    }

}
